package com.like.banzipao.server

import com.like.banzipao.server.db.DatabaseConfig
import com.like.banzipao.server.db.DatabaseHelper
import com.like.banzipao.server.plugins.configureRouting
import com.like.banzipao.server.plugins.configureSecurity
import com.like.banzipao.server.plugins.configureSerialization
import com.like.banzipao.server.plugins.configureSockets
import com.like.banzipao.server.plugins.configureStatusPages
import io.ktor.server.application.Application
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty

fun main() {
    embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module)
        .start(wait = true)
}

fun Application.module() {
    DatabaseHelper.initDatabase(
        DatabaseConfig(
            driverClassName = "com.mysql.cj.jdbc.Driver",
            url = "jdbc:mysql://localhost:3306/banzipao",
            username = "root",
            password = "admin",
        )
    )
    configureSecurity()
    configureSockets()
    configureSerialization()
    configureRouting()
    configureStatusPages()
}
